/**
 * 
 */
package net.looker.monitor.checker;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Logger;

import net.looker.data.News;
import net.looker.monitor.modifier.DispatcherManager;
import net.looker.monitor.modifier.UpdateModifier;
import net.looker.monitor.schdule.NewsManager;


/**新闻更新检查器
 * 检查新闻更新
 * @author solosky
 *
 */
public class UpdateChecker extends Checker 
{
	
	public UpdateChecker(NewsManager newsManager) 
	{
		super(newsManager);
	}

	/* (non-Javadoc)
	 * @see net.looker.news.site.category.checker.Checker#match()
	 */
	@Override
	public void check()
	{
		//如果两次新闻列表存在，并且两次的新闻正文的HASH不一致即为新闻更新了
		//得到最新新闻列表迭代对象
		Iterator<News> it = newsManager.getCurNewsList().iterator();
		//遍历所有的最新新闻
		News curNews = null;
		News lastNews = null;
		while (it.hasNext())
		{
			curNews  = it.next();
			lastNews = newsManager.getLastNews(curNews.getNewsHash());
			if (lastNews!=null && !curNews.getContentHash().equals(curNews.getContentHash()))
			{
				Logger.getLogger("looker").info("更新新闻："+curNews.toString());
				DispatcherManager.update( new UpdateModifier(curNews));
			}
		}
	}

}
